package common.util;

import common.util.generate.service.GenerateService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 文件生成
 *
 * @author liubo
 * @created 2020-06-23 10:07
 */
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {GenerateApplication.class})
public class GenerateFile {

    @Autowired
    private GenerateService generateService;

    @Test
    public void generate() throws Exception {
        File dirFile = new File("D:\\project\\idea_project\\third_hospital\\logs");

        deleteFile(dirFile);
    }

    private boolean deleteFile(File dirFile) {
        if (!dirFile.exists()) {
            return false;
        }

        if (dirFile.isFile()) {
            return dirFile.delete();
        } else {

            for (File file : dirFile.listFiles()) {
                deleteFile(file);
            }
        }

        return dirFile.delete();
    }

}
